package com.cysion.study.ui

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.content.res.ResourcesCompat
import android.view.View
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.base.BaseFragmentAdapter
import com.cysion.study.ktbox.utils.darkTextTheme
import com.cysion.other.color
import com.cysion.targetfun._addOnPageChangeListener
import com.cysion.study.uibox.bar.TopBar
import com.cysion.study.R
import com.cysion.study.ui.fragment.CourseWeekFragment
import kotlinx.android.synthetic.main.activity_course.*
import java.util.*

//我的课表
class CourseMoreActivity : BaseActivity(), View.OnClickListener {


    override fun getLayoutId(): Int = R.layout.activity_course
    private lateinit var mFragments: MutableList<Fragment>
    private lateinit var mTitles: MutableList<String>
    override fun initView() {
        darkTextTheme(color(R.color.main_cl))
        topbar.apply {
            setTitle("我的课表")
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.LEFT) {
                    finish()
                }
            }
        }
        tv_qj.setOnClickListener(this)
        tv_bx.setOnClickListener(this)
        tv_tx.setOnClickListener(this)
        inViewq()//默认请假tab页面

        vp_content.offscreenPageLimit = 3


        mFragments = getFragments()
        mTitles = getTitles()
        vp_content.adapter = BaseFragmentAdapter(this.supportFragmentManager, mFragments, mTitles)
        vp_content._addOnPageChangeListener {
            _onPageSelected {
                when (it) {
                    1 -> {
                        inViewb()//本月
                        vp_content.currentItem = it

                    }
                    2 -> {
                        inViewt()//全部
                    }
                    else -> {
                        inViewq()//本周
                    }
                }
            }
        }
    }


    private fun getTitles(): MutableList<String> {
        val strings = ArrayList<String>()
        strings.add("本周")
        strings.add("本月")
        strings.add("全部")
        return strings
    }

    private fun getFragments(): MutableList<Fragment> {
        val fragmentArrayList = ArrayList<Fragment>()
        val c1 = CourseWeekFragment()
        val c2 = CourseWeekFragment()
        val c3 = CourseWeekFragment()
        val b1 = Bundle()
        val b2 = Bundle()
        val b3 = Bundle()
        b1.putString("type", "1")
        c1.arguments = b1
        fragmentArrayList.add(c1)//本周

        b2.putString("type", "2")
        c2.arguments = b2
        fragmentArrayList.add(c2)//本周

        b3.putString("type", "3")
        c3.arguments = b3
        fragmentArrayList.add(c3)//本周
//        fragmentArrayList.add(CourseWeekFragment())//本月
//        fragmentArrayList.add(CourseWeekFragment())//全部
        return fragmentArrayList
    }


    var type: String = "0"//审批类型: 0.请假 1.报销 2.调休
    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_qj -> {//本周
//                tv_qj.background = resources.getDrawable(R.drawable.login_bg)
                inViewq()
                vp_content.currentItem = 0
                type = "0"
            }
            R.id.tv_bx -> {//本月
                type = "1"
                vp_content.currentItem = 1
                inViewb()
            }
            R.id.tv_tx -> {//全部
                type = "2"
                vp_content.currentItem = 2
                inViewt()
            }
        }
    }


    private fun inViewq() {
        tv_qj.background = ResourcesCompat.getDrawable(getResources(), R.drawable.blue_bg, null)
        tv_bx.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tv_tx.background = null
        tv_qj.setTextColor(resources.getColor(R.color.white))
        tv_bx.setTextColor(resources.getColor(R.color.main_cl))
        tv_tx.setTextColor(resources.getColor(R.color.main_cl))
    }

    private fun inViewb() {
        tv_qj.background = null
        tv_bx.background = ResourcesCompat.getDrawable(getResources(), R.drawable.blue_bg, null)
        tv_tx.background = null
        tv_qj.setTextColor(resources.getColor(R.color.main_cl))
        tv_bx.setTextColor(resources.getColor(R.color.white))
        tv_tx.setTextColor(resources.getColor(R.color.main_cl))
    }

    private fun inViewt() {
        tv_qj.background = null
        tv_bx.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tv_tx.background = ResourcesCompat.getDrawable(getResources(), R.drawable.blue_bg, null)
        tv_qj.setTextColor(resources.getColor(R.color.main_cl))
        tv_bx.setTextColor(resources.getColor(R.color.main_cl))
        tv_tx.setTextColor(resources.getColor(R.color.white))
    }

    override fun closeMvp() {
    }

}
